package com.game.ctrler
{
	import com.game.data.vo.GameGadgetVO;
	import com.game.manager.SettingManager;
	import com.game.view.component.GameGadgetType;
	import com.game.view.component.IndicateGadget;
	
	import config.Config;
	
	public class GadgetQueue
	{
		
		public function GadgetQueue()
		{
			super();
		}
		
		private var _mon:Array = [];
		private var _hero:Array = [];
		private var _pet:Array = [];
		private var _prior:Array = [];
		
		private var _interval:uint = 0;
		private const _intervalCount:uint = 3;
		
		public function get gc():Config
		{
			return Config.getIns();
		}
		
		private function getAllType():Array
		{
			return [_mon, _hero, _pet, _prior];
		}
		
		public function addGadgetToQueue(vo:GameGadgetVO):void
		{
			if(!SettingManager.getSettingVO().isShowIndicate)
			{
				return;
			}
			if(GameGadgetType.isPrior(vo.type))
			{
				_prior.push(vo);
			}
			if(GameGadgetType.isForHero(vo.type))
			{
				_hero.push(vo);
			}
			if(GameGadgetType.isForMonster(vo.type))
			{
				_mon.push(vo);
			}
			if(GameGadgetType.isForPet(vo.type))
			{
				_pet.push(vo);
			}
		}
		
		public function renderAnimate():void
		{
			if(_interval > 0)
			{
				_interval--;
				return;
			}
			showCure();
			_interval = _intervalCount;
		}
		
		public function destroy():void
		{
			for each (var arr:Array in getAllType)
			{
				arr.length = 0;
			}
		}
		
		public function showCure():void
		{
			var all:Array = getAllType();
			for each (var arr:Array in all)
			{
				if(arr.length == 0)
				{
					continue;
				}
				if(arr.length > 5)
				{
					showSingleCure(arr.shift(),-20, -20);
					showSingleCure(arr.shift(),-10, -10);
					showSingleCure(arr.shift(),10, -10);
					showSingleCure(arr.shift(),20, -20);
				}
				showSingleCure(arr.shift())
			}
		}
		
		private function showSingleCure(vo:GameGadgetVO,offsetX:Number = 0, offsetY:Number = 0):void
		{
			var num:IndicateGadget = new IndicateGadget();
			num.value = vo.value;
			num.setGadgetType(vo.type);
			num.x = vo.position.x + offsetX;
			num.y = vo.position.y + offsetY;
			num.x -= num.width / 2;
			num.y -= num.height;
			gc.gameScene.addChild(num);
		}
	}
}
